package com.hongpu.utils;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;

/**
 * oa 日期工具类
 *
 * @author 张玉胜
 * @since 2025年06月12日
 */
public class OaDateUtils {

    /**
     * 获取上个月的第一天
     * @return
     */
    public static String firstDayOfLastMonth() {
        LocalDate firstDayOfLastMonth = LocalDate.now().withDayOfMonth(1).minusMonths(1);
        return firstDayOfLastMonth.toString();
    }

    /**
     * 获取上个月的最后一天
     * @param args
     */
    public static String lastDayOfLastMonth(){
        LocalDate firstDayOfLastMonth = LocalDate.now().withDayOfMonth(1).minusMonths(1);
        LocalDate lastDayOfLastMonth = YearMonth.of(firstDayOfLastMonth.getYear(), firstDayOfLastMonth.getMonth()).atEndOfMonth();
        return lastDayOfLastMonth.toString();
    }
    /**
     * 传入月份，获取这个月份的第一天
     * @param month 数据格式： 2025-06
     */
    public static String firstDayOfMonth(String month){
        LocalDate  firstDayOfMonth = YearMonth.parse(month, DateTimeFormatter.ofPattern("yyyy-MM")).atDay(1);
        return firstDayOfMonth.toString();
    }

    /**
     * 传入月份，获取这个月份的最后一天
     * @param month 数据格式： 2025-06
     */
    public static String lastDayOfMonth(String month){
        LocalDate  firstDayOfMonth = YearMonth.parse(month, DateTimeFormatter.ofPattern("yyyy-MM")).atDay(1);
        LocalDate lastDayOfLastMonth = YearMonth.of(firstDayOfMonth.getYear(), firstDayOfMonth.getMonth()).atEndOfMonth();
        return lastDayOfLastMonth.toString();
    }



}